package com.qiangesoft.blog.controller.manage;

import com.qiangesoft.blog.common.annotation.OperationLog;
import com.qiangesoft.blog.common.mvc.PageQuery;
import com.qiangesoft.blog.common.mvc.PageResultVO;
import com.qiangesoft.blog.system.entity.SysRole;
import com.qiangesoft.blog.system.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色管理 前端控制器
 * </p>
 *
 * @author qiange
 */
@RestController
@RequestMapping("/system/role")
@Api(tags = "角色管理-接口")
@RequiredArgsConstructor
public class SysRoleController {

    private final ISysRoleService roleService;

    @GetMapping
    @ApiOperation(value = "角色列表")
    public PageResultVO<SysRole> list(PageQuery pageQuery, String name) {
        return roleService.listRole(pageQuery, name);
    }

    @GetMapping(value = "/all")
    @ApiOperation(value = "全部角色列表")
    public List<SysRole> list(String name) {
        return roleService.listAllRole(name);
    }

    @PostMapping
    @ApiOperation(value = "添加角色")
    @OperationLog(value = "添加角色")
    public void insert(@RequestBody SysRole role) {
        roleService.insertRole(role);
    }

    @PutMapping
    @ApiOperation(value = "修改角色")
    @OperationLog(value = "修改角色")
    public void update(@RequestBody SysRole role) {
        roleService.updateRole(role);
    }

    @DeleteMapping(value = "/remove")
    @ApiOperation(value = "删除角色")
    @OperationLog(value = "删除角色")
    public void deleteBatch(@RequestBody List<Long> ids) {
        roleService.deleteBatch(ids);
    }

    @GetMapping(value = "/queryUserRole")
    @ApiOperation(value = "获取当前登录用户所拥有的权限")
    public List<Long> getCurrentUserRole() {
        return roleService.getCurrentUserRole();
    }

    @GetMapping(value = "/queryRoleId")
    @ApiOperation(value = "获取该角色所有的权限")
    public List<Long> selectById(Long roleId) {
        return roleService.selectById(roleId);
    }
}
